#include "ElementDoor.h"

ElementDoor::ElementDoor(vector3<int> pos)
{
    type=DOOR;
    activated=false;
    isCollidable=true;
    faceSide = false;
    aniDoor.stop();

    geometry = AABB(vector3<float>(0,0,0),vector3<float>(1,2,0.3));
    translate(pos.cast<float>());
}

void ElementDoor::invokeCollisionEvent(Character*){
    //activate();
}

void ElementDoor::invokeActivateEvent(){
    if(!activated)activate();
    else deactivate();
}

void ElementDoor::invokeUpdateEvent(Character *c){

}

void ElementDoor::activate(){
        if(activated)return;
        activated=true;
        isCollidable=false;

        aniDoor.playForward();
        aniDoor.reset();
}

void ElementDoor::deactivate(){
        if(!activated)return;
        activated=false;
        isCollidable=true;

        aniDoor.playReverse();
        aniDoor.reset();
}



void ElementDoor::render(){
    glPushMatrix();

    glTranslatef(s.position.x,s.position.y,s.position.z);
    if(faceSide){
        glTranslatef(0,0,1);
        glRotatef(90,0,1,0);
    }
    aniDoor.render();
    glPopMatrix();
}
